<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水平垂直居中</title>
    <style>
        /* 1.绝对定位  使用transfrom*/
        /* .parent {
            position: relative;
            height: 300px;
            border: 1px solid red;
        }

        .child {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            border: 1px solid blue;
        } */
        /* 绝对定位 盒子自身有宽高 margin居中 */
       /*  .parent {
            position: relative;
            height: 300px;
            border: 1px solid red;
        }

        .child {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            width: 300px;
            height: 100px;
            border: 1px solid blue;
        } */

        /* 绝对定位  使用宽高的一般 */
      /*   .parent {
            position: relative;
            height: 300px;
            border: 1px solid red;
        }

        .child {
            position: absolute;
            top: 50%;
            left: 50%;
            margin-left: -150px;
            margin-top: -50px;
            width: 300px;
            height: 100px;
            border: 1px solid blue;
        } */

        /* 使用flex */
        .parent{
            display: flex;
            justify-content: center;
            align-items: center;
            height: 300px;
            border: 1px solid red;
        }
        .child {
            width: 300px;
            height: 100px;
            border: 1px solid blue;
        } 
    </style>
</head>

<body>
    <div class="parent">
        <div class="child">
            child
        </div>
    </div>
</body>

</html>